<template>
  <div class="common-layout">
    <el-container>
      <el-header style="font-size: 30px;border: 3px solid #ccc; background-color:blue">
        <span style="float: right;">欢迎:{{pinia.account.UserName}}【{{pinia.account.RoleName}}】登录<el-button type="danger" @click="out" style="margin-left: 10px;">退出</el-button></span>
      </el-header>
      <el-container>

        <el-aside style="border: 3px solid #ccc; width:200px;">
        <!-- active-text-color="#ffd04b"
        background-color="#545c64"
        class="el-menu-vertical-demo"
        default-active="2"
        text-color="#fff"
        @open="handleOpen"
        @close="handleClose"
        router
      > -->
      
          <!-- <el-menu-item index="1-2">首页</el-menu-item>
          <el-menu-item index="/menu">菜单管理</el-menu-item>
          <el-menu-item index="/user">用户管理</el-menu-item>
          <el-menu-item index="/role">角色列表管理</el-menu-item>
        <el-menu-item index="/permission">角色权限管理</el-menu-item>
      -->
          <el-menu :default-active="$route.path" router>
          <MenuTree :menus="menuTree" />
          </el-menu>
          

        </el-aside>

        <el-main><RouterView /></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { Read,Write } from '@/http/interceptors'
import axios from 'axios'
import{ref} from 'vue'
import {useCounterStore} from '@/stores/counter'
const pinia=useCounterStore();
import { useRouter } from 'vue-router'
const router=useRouter();
import MenuTree from './MenuTree.vue'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'

//菜单树
const menuTree = ref<any[]>([]);
// 假设你已经拿到用户的角色ID数组 userRoleIds
Read.post("/api/MenuGetUserMenuTree/GetUserMenuTree", { roleIds:pinia.account.RoleId })
  .then(res => {
    // res.data 就是树形菜单
    menuTree.value=res.data
});


//退出
const out=()=>{
  router.push('/login')
}


const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>
